﻿#ifndef POSTESTWIDGET_H
#define POSTESTWIDGET_H


#include <QWidget>
#include <QGridLayout>
#include <QPushButton>
#include <QSlider>
#include <qstackedwidget.h>
#include "qcustomplot.h"
#include "define.h"
#include "capcontroldefine.h"
#include "logwidget.h"
#include "quiqss.h"


class QPosTestWidget : public QWidget
{
    Q_OBJECT
public:
    explicit QPosTestWidget(QWidget *parent = nullptr);
    void InitUI();

    QWidget* createParamWidget();
    QWidget* createAxisWidget();

    QWidget* createGroudTestWidget();

    QWidget* createSignalWidget();
    QWidget* createPosSetwidget();

    void rcvFrameData(st_loopbackdata rcvdata);

    void rcvFrameData(st_rcvdata rcvdata);

    void rcvFrameData(st_loopdata_AA rcvdata);

    void rcvFrameData11(st_loopdata_11 rcvdata);


    void plotPosData();

    void plotSpeedData();

    void writeDataToFile(QString str);

    void saveDataToFile();


    void setPlotStyle(QCustomPlot* pPlot,QString xName,QString yName);
    void setPosPlotStyle(QCustomPlot* pPlot,QString xName,QString yName);

    void setButtonStyleSheet(QPushButton* pBtn);

signals:
    void signal_startTest(int i32Axis,int workmode,int data,int data1);

    void signal_framedata(QVariant var);

    void signal_setpid(int i32AxisNo,int nType,float lfkp,float lfki,float lfkd);//ntype 1-电流环 2-速度环 3-位置环
//    void signal_set_thresholdparam(int i32Aixs,int cmdid,int i32value,int datalen);


public slots:
    void onShowPIDParam(int cmdid,float lfKP,float lfKI,float lfKD);//显示pid参数

    void onAxiBtnClick(int id);

    void onStartBtnClicked();

    void onStopBtnClicked();

    void onSetParamBtnClicked();

    void onModifyParamBtnClicked();

    void onEnabelBtnClicked();

    void onSaveDataBtnClick();

private:
    QCustomPlot* _pPosPlot;//电流值反馈
    QCustomPlot* _pSpeedPlot;//电流值反馈

    QLogWidget* _pLogWidget;

    QStackedWidget* _pStackedWidget;




    QButtonGroup* _pAxisBtnGroup;
    int _i32AixsNo;//轴编号

    //参数设置界面
    QComboBox* _pSignalTypeComBox;
    QLineEdit* _pFreqEdit;
    QLineEdit* _pAmpEdit;

    //测试类型
    QComboBox* _pTestTypeComBox;
    QLineEdit* _pSetPosEdit;

    QComboBox* _pFrontFeedComBox;



    QPushButton* _pSetParamBtn;//修改参数
    QPushButton* _pModifyParamBtn;//注入参数
    QPushButton* _pEnabelBtn;//前馈使能
    QLineEdit* _pKPEdit;
    QLineEdit* _pKIEdit;
    QLineEdit* _pKDEdit;

    QLabel* _pShowDataLabel;

    QPushButton* _pStartBtn;
    QPushButton* _pStopBtn;

    QSlider* _pCurrentValueSlider;
    QLineEdit* _pCurrentValueEdit;

    QWidget* _pParamWidget;
    QWidget* _pAxisSelectWidget;

    QTimer* _pPlotDataTimer;

    st_loopbackdata _rcvframedata;
    st_rcvdata _rcv_capdata;
    st_loopdata_AA _frameAAData;

    float _lfPosSetdata;
    float _lfPosResponsedata;

    float _lfSpeedSetdata;
    float _lfSpeedResponsedata;

    bool _bStartTest;

    QVector<double> _xposdatalist;
    QVector<double> _yposlist[2];
    QVector<double> _yspeedlist[2];
    QVector<double> _xspeeddatalist;


    int _i32FrameCnt;
    int _i32AAFrameCnt;

    QLabel* _pShowPosInfoLabel;
    QCheckBox* _pSaveDataCheckBox;


    bool _bStartSaveData;

    QFile m_savefile;

    int _i32SaveFrameCnt;

    QString m_sSaveDataInfo;

    //保存数据时使用变量
    float lfAziSpeedResponse;
    float lfAziSpeedSet;
    float lfPitchSpeedResponse;
    float lfPitchSpeedSet;
    float lfAziQResponsedata;
    float lfAziQSetdata;
    float lfPitchQResponsedata;
    float lfPitchQSetdata;

     float lfAziCurrentA;
     float lfAziCurrentC;
     float lfPitchCurrentA;
     float lfPitchCurrentC;

     float lfAziPosResponse;
     float lfAziPosSet;
     float lfPitchPosResponse;
     float lfPitchPosSet;



};

#endif // CURRENTADJWIDGET_H

